using UnityEngine;
using System.Collections;

public class mainMenu : MonoBehaviour {

	public GUIStyle welcomeLabel;
	public GUISkin customSkin;
	public Rect playGameRect;
	public Rect optionsRect;
	public Rect quitRect;
	
	private bool optionsMode = false;
	
	public float enemiesAmount  = 30;
	public float enemiesDelay = 0.5f;
	public float shootDelay = 0.1f;
	
	private bool menuMode = true;   //1
	private bool gameMode = false;  //1
	private globalVarsClass gv;
	
	private int pauseTime = 0;

	void Awake(){
    	DontDestroyOnLoad(this);
	}

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnGUI(){         //3
	    // Debug.Log("catch");
		pauseTime++;
	     if (Input.GetKeyDown(KeyCode.Escape)){  //2
	      //  Time.timeScale = 0;   
			if(pauseTime<10)return;
			pauseTime = 0;
	        //Debug.Log(menuMode); 
	      	   // menuMode = true;                //1
	     	   // optionsMode = false; 
			if(menuMode == true){          //3
	       		//Debug.Log("hide"); 
				menuMode = false;
				if(gameMode){
		       		gv = GameObject.Find("GlobalVariables").GetComponent<globalVarsClass>();
	      			gv.setPause(false);
				}
			}else{          //3
	       		//Debug.Log("show"); 
				menuMode = true;	           
	     	    optionsMode = false; 
				if(gameMode){
		       		gv = GameObject.Find("GlobalVariables").GetComponent<globalVarsClass>();
	      			gv.setPause(true);
				}
			}
	       /* if(!menuMode){            
	      	    menuMode = true;                //1
	     	    optionsMode = false;         //1
				if(gameMode){
		       		gv = GameObject.Find("GlobalVariables").GetComponent<globalVarsClass>();
	      			gv.setPause(true);
				}
	        }*//*else{
		        menuMode = false;                //1
		       // optionsMode = true;           //1
				if(gameMode){
		       		gv = GameObject.Find("GlobalVariables").GetComponent<globalVarsClass>();
	      			gv.setPause(false);
				}
			}*/
	    }
	
	    if(menuMode){
	        if(!optionsMode){                       
	                        
	            GUI.Label(new Rect(Screen.width / 2, 0, 50, 20), "Welcome",welcomeLabel);
	                
	            GUI.skin = customSkin;
	                        
	            if(!gameMode){              //1
	                if(GUI.Button(playGameRect, "Play Game")){
	                    menuMode = false;   //1
	                    gameMode = true;    //1
	                    //Time.timeScale = 1; //3
	                    Application.LoadLevel("gameScene");
	                }
	            }else{
	                if(GUI.Button(playGameRect,"Resume")){
	                  	gv = GameObject.Find("GlobalVariables").GetComponent<globalVarsClass>();
	      				gv.setPause(false);
	                    menuMode = false;   //1
	                }
	            }
	                        
	            if(GUI.Button(optionsRect,"Options")){
	                optionsMode = true;
	            }
	                        
	            if(GUI.Button(quitRect,"Quit")){
	                Application.Quit();
	            }
	                        
	        }else{
	                                                        
	            GUI.Label(new Rect(Screen.width / 2, 0, 50, 20),"Options",welcomeLabel);
	                        
	            GUI.skin = customSkin;
	                        
	            GUI.Label(new Rect(270, 75, 50, 20), "Bullet Impulse");
	            enemiesAmount = GUI.HorizontalSlider(new Rect(50, 100, 500, 20), enemiesAmount,1,100);
	            GUI.Label(new Rect(560, 95, 50, 20), enemiesAmount.ToString());
	                        
	            GUI.Label(new Rect(270, 125, 50, 20), "Enemies delay");
	            enemiesDelay = GUI.HorizontalSlider(new Rect(50, 150, 500, 20), enemiesDelay,0.1f,5);
	            GUI.Label(new Rect(560, 145, 50, 20), enemiesDelay.ToString());
			
	            GUI.Label(new Rect(270, 175, 50, 20), "Shoot Delay");
	            shootDelay = GUI.HorizontalSlider(new Rect(50, 200, 500, 20), shootDelay,0.01f,1);
	            GUI.Label(new Rect(560, 195, 50, 20), shootDelay.ToString());
	                        
	            if(GUI.Button(new Rect(20, 240, 100, 30), "<< Back")){
	                optionsMode = false;
	            }
	        
	        }
	    }
	}
	
}
//public GUIStyle welcomeLabel;
//public GUISkin customSkin;
//public Rect playGameRect;
//public Rect optionsRect;
//public Rect quitRect;


//public var welcomeLabel : GUIStyle;
//ublic var customSkin : GUISkin;
//public var playGameRect : Rect;
//public var optionsRect : Rect;
//public var quitRect : Rect;


//private bool optionsMode = false;
//
//public float _bulletImpulse  = 300;
//public float _shootDelay = 1;

//private var optionsMode = false;
//
//public var _bulletImpulse : float = 300;
//public var _shootDelay : float = 1;

/*void OnGUI(){
    if(!optionsMode){
        GUI.Label(new Rect(Screen.width / 2, 0, 50, 20),"Welcome",welcomeLabel);

        GUI.skin = customSkin;

        if(GUI.Button(playGameRect,"Play Game")){
            Application.LoadLevel("Test Scene");  //1
        }
           
        if(GUI.Button(optionsRect,"Options")){
            optionsMode = true;
        }
                   
        if(GUI.Button(quitRect,"Quit")){
            Application.Quit();                   //2
        }
                   
    }else{
                                           
        GUI.Label(new Rect(Screen.width / 2, 0, 50, 20), "Options",welcomeLabel);
                   
        GUI.skin = customSkin;
                   
        GUI.Label(new Rect(270, 75, 50, 20),"Bullet Impulse");
        _bulletImpulse = GUI.HorizontalSlider(new Rect(50, 100, 500, 20),_bulletImpulse,10,700);
        GUI.Label(new Rect(560, 95, 50, 20),_bulletImpulse.ToString());
           
        GUI.Label(new Rect(270, 125, 50, 20),"Shoot Delay");
        _shootDelay = GUI.HorizontalSlider(new Rect(50, 150, 500, 20),_shootDelay,0.1,3);
        GUI.Label(new Rect(560, 145, 50, 20),_shootDelay.ToString());
                   
        if(GUI.Button(new Rect(20, 190, 100, 30),"<< Back")){
            optionsMode = false;
        }
           
    }  
                           
}*/
